﻿using LBSoft.Common.DotNetCode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace LBSoft.HplusAdmin
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            //防止SQL注入关键字符
            bool result = false;
            result = SqlFilterHelper.ValidUrlData(Request.RequestType.ToUpper());
            if (result)
            {
                base.Server.ClearError();
                base.Application["error"] = "提交的数据有恶意字符";
                base.Response.Redirect("~/Error/ErrorPage.aspx");
            }
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception objErr = base.Server.GetLastError().GetBaseException();
            string error = objErr.Message ?? "";
            if (error.IndexOf("100|") >= 0)
            {
                base.Server.ClearError();
                base.Response.Redirect("~/Index.aspx?ReturnUrl=" + error.Replace("100|", ""));
            }
            else
            {
                //base.Server.ClearError();
                //base.Application["error"] = error;
                //base.Response.Redirect("~/Error/ErrorPage.aspx");
            }
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}